<template>
	<view class="mainPage edit-data" :style="{'padding-top': `${$store.state.safeArea.top || 0}px`, 'padding-bottom': `${$store.state.safeArea.bottom || 0}px`}">
		<public-head :title="title"></public-head>
		<view class="info">
			<view>
				<u-field v-model="hospital" label="就职医院:" placeholder="请填写您所就职的医院名称" right-icon="arrow-right" @input="inputs()"></u-field>
				<u-field v-model="address" label="医生地址:" disabled="true" placeholder="请填写医生地址"></u-field>
				<u-field v-model="informationlist.description" label="医生寄语:" placeholder="填写示例：耐心、细心、放心收费处微笑服务、满意服务。" type="textarea"></u-field>
				<u-field v-model="informationlist.skills" label="擅长领域:" placeholder="填写示例：关节疾病：常见关节炎，关节疼痛治疗，创伤，骨折；" type="textarea" maxlength="150" required></u-field>
				<u-field v-model="informationlist.experience" label="医生经历:" placeholder="填写示例：医学博士。毕业于北京大学八年制本博连读专业" type="textarea" maxlength="150" required></u-field>
			</view>
			<view class="listtit" v-if="show1">
				<view style="padding: 10rpx 0;color: #FE7600; font-size: 26rpx;" @click="addhost">没有医院？点这儿</view>
				<view class="title" v-for="(item,index) in hosplist" :key="index" @click="hosp(index)">
					{{item.hospital_name}}
					<view style="font-size: 12px; color: #C0C4CC;">
						{{item.address}}
					</view>
				</view>
			</view>
		</view>
		<view class="but">
			<button @click="preservation">提交</button>
		</view>
		<!-- 提示框 提交审核成功再次进入审核中提示-->
		<u-modal v-model="tips" :content="content" @confirm="confirmone"></u-modal>
		<!-- 不通过提示 -->
		<u-modal v-model="failtips" title="审核失败" :content="failcontent" @confirm="failconfirm"></u-modal>
	</view>
</template>
<script>
var that
import publicHead from "@/components/publicHead/publicHead.vue"
export default {
	components: {
		publicHead
	},
	data() {
		return {
			title: "我的档案",
			hospital: '',
			code: '',
			show1: false,
			hosplist: '',
			informationlist: '',
			hospital_id: '',
			address: '',
			tips: false,
			failtips: false,
			verify_data: '',
			content: '您的档案已提交成功，预计1~2个工作日内完成审核，请耐心等待~',
			failcontent: ''
		}
	},
	onLoad() {
		that = this
		that.obtain()
	},
	methods: {
		tohospitalname() {
			uni.navigateTo({
				url: './hospitalname'
			})
		},
		tohospitaladdress() {
			uni.navigateTo({
				url: 'hospitaladdress'
			})
		},
		inputs() {
			if (that.hospital.length < 1) {
				that.show1 = false
				console.log('显示列表')
			} else {
				that.$postAjax1('Doctorsside_search_hospital', {
					keyword: that.hospital
				}, function (data) {
					that.hosplist = data.data.data
					that.address = that.hosplist.address
					console.log('模糊搜索内容', that.hosplist)
				})
				console.log('请求')
				that.show1 = true
			}
			if (that.hospital == '') {
				that.address = ''
			}
		},
		hosp(index) {
			that.hospital = that.hosplist[index].hospital_name
			that.hospital_id = that.hosplist[index].id
			that.address = that.hosplist[index].address//医生地址
			console.log('选取了', that.hospital, that.hospital_id, index)
			that.show1 = false
		},
		obtain() {
			that.$postAjax1('Doctorsside_view_edit', {
			}, function (data) {
				if (data.data.data.verify_data) {
					that.informationlist = data.data.data.verify_data
				} else {
					that.informationlist = data.data.data
				}
				// that.informationlist = data.data.data
				// that.verify_data=data.data.data.verify_data
				that.hospital = data.data.data.hospital_name
				that.hospital_id = data.data.data.hospital_id
				that.address = data.data.data.address
				if (data.data.data.verify_data.status == 0) {
					that.tips = true
				} else if (data.data.data.verify_data.status == 2 && data.data.data.verify_data.read == 0) {
					that.failtips = true
					// 错误提示语
					that.failcontent = '失败原因：' + data.data.data.verify_data.failed_reason
				}
				console.log('请求数据', that.informationlist)
			})
		},
		preservation() {
			// if (that.informationlist.doc_address == '' || that.informationlist.doc_address == null || that.informationlist.doc_address == 'null') {
			// 	uni.showToast({
			// 		title: '医生地址不能为空',
			// 		icon: 'none',
			// 		duration: 2000
			// 	});
			// } else 
			if (that.informationlist.skills == '' || that.informationlist.skills == null || that.informationlist.skills == 'null') {
				uni.showToast({
					title: '擅长领域不能为空',
					icon: 'none',
					duration: 2000
				});
			} else if (that.informationlist.experience == '' || that.informationlist.experience == null || that.informationlist.experience == 'null') {
				uni.showToast({
					title: '医生经历不能为空',
					icon: 'none',
					duration: 2000
				});
			} else {
				that.$postAjax1('Doctorsside_edits_info', {
					// hospital_id: that.hosplist == '' ? '' : that.hospital_id, 
					hospital_id: that.hospital == '' || that.hospital == null ? '' : that.hospital_id == '' || that.hospital == null ? '' : that.hospital_id,
					hospital_name: that.hospital == '' || that.hospital == null ? '' : that.hospital,
					// address: that.address,
					// doc_address: that.informationlist.doc_address,
					doc_address: that.address == '' || that.address == null ? '' : that.address,
					description: that.informationlist.description,
					skills: that.informationlist.skills,
					experience: that.informationlist.experience
				}, function (data) {
					that.tips = true
				})
			}
		},
		addhost() {
			uni.navigateTo({
				url: '../../../pages/register/hospital'
			})
		},
		confirmone() {
			that.tips = false
		},
		failconfirm() {
			that.$postAjax1('Doctorsside_view_edit', {
				operate_read: 1
			}, function (data) {
				console.log('知道失败了')
			})
			that.failtips = false
		}
	}
}
</script>
<style lang="scss">
.u-field {
	padding: 10px 0px !important;
}
</style>
<style scoped lang="scss">
.edit-data {
	background: #fafafa;
	width: 100vw;
	height: 100vh;
	//min-height: 100vh;
	position: relative;
	.top {
		margin-bottom: 22rpx;
		background-color: #ffffff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		width: 100%;
		.left {
			font-size: 32rpx;
			font-weight: 400;
			color: #242424;
			line-height: 44rpx;
		}
		.title {
			font-size: 32rpx;
			font-weight: 500;
			color: #242424;
			line-height: 44rpx;
		}
	}
	.info {
		position: relative;
		padding: 0 58rpx;
		box-sizing: border-box;
		background-color: #ffffff;
		margin-top: 20rpx;
		.head-portrait {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 16rpx 0 10rpx;
			border-bottom: 2rpx solid #ebebeb;
			.left {
				font-size: 28rpx;
				font-weight: 400;
				color: #616161;
				line-height: 40rpx;
			}
			.right {
				.touxiang {
					display: inline-block;
					width: 94rpx;
					height: 94rpx;
					vertical-align: middle;
					border-radius: 50%;
				}
				.jiantou {
					vertical-align: middle;
					margin-left: 46rpx;
					display: inline-block;
					width: 10rpx;
					height: 19rpx;
				}
			}
		}
		.nickname {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 0;
			border-bottom: 1rpx solid #f9f2f2;
			.left {
				font-size: 28rpx;
				font-weight: 400;
				color: #616161;
				line-height: 40rpx;
			}
			.right {
				text {
					font-size: 28rpx;
					font-weight: 400;
					color: #616161;
					line-height: 40rpx;
					padding: 34rpx 0;
					vertical-align: middle;
				}
				image {
					vertical-align: middle;
					display: inline-block;
					width: 10rpx;
					height: 19rpx;
					margin-left: 20rpx;
				}
			}
		}
		.id-number {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 0;
			border-bottom: 2rpx solid #ebebeb;
			.left {
				font-size: 28rpx;
				font-weight: 400;
				color: #616161;
				line-height: 40rpx;
			}
			.right {
				text {
					font-size: 28rpx;
					font-weight: 400;
					color: #616161;
					line-height: 40rpx;
					padding: 34rpx 0;
					vertical-align: middle;
					margin-right: 36rpx;
				}
			}
		}
		.sex,
		.birthday,
		.region,
		.brief-introduction {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 0;
			border-bottom: 1rpx solid #f9f2f2;
			.form {
				text-align: right;
			}
			.left {
				font-size: 28rpx;
				font-weight: 400;
				color: #616161;
				line-height: 40rpx;
			}
			.right {
				text {
					font-size: 28rpx;
					font-weight: 400;
					line-height: 40rpx;
					padding: 34rpx 0;
					vertical-align: middle;
					color: #919191;
				}
				image {
					vertical-align: middle;
					display: inline-block;
					width: 10rpx;
					height: 19rpx;
					margin-left: 20rpx;
				}
			}
		}
		.background {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 34rpx 0;
			.left {
				font-size: 28rpx;
				font-weight: 400;
				color: #616161;
				line-height: 40px;
			}
			.right {
				image {
					&:nth-of-type(1) {
						display: inline-block;
						width: 194rpx;
						height: 98rpx;
						vertical-align: middle;
						border-radius: 20rpx;
					}
					&:nth-of-type(2) {
						vertical-align: middle;
						display: inline-block;
						width: 10rpx;
						height: 19rpx;
						margin-left: 20rpx;
					}
				}
			}
		}
		.listtit {
			position: absolute;
			top: 90rpx;
			width: 90%;
			padding: 20rpx 30rpx;
			background: #ffffff;
			border-radius: 0rpx 0rpx 20rpx 20rpx;
			border: 1rpx #e7e7e7 solid;
			opacity: 1;
			z-index: 999;
			.title {
				padding: 10rpx 0;
			}
		}
	}
	.but {
		position: absolute;
		bottom: 196rpx;
		//margin-top: 200rpx;
		width: 100%;
		button {
			width: 90%;
			opacity: 1;
			color: #ffffff;
			background: #ff8f2b;
			box-shadow: 0px 6px 8px 0px rgba(255, 143, 43, 0.2);
			border-radius: 46px;
		}
	}
}
</style>
